package com.century.sjt.logic;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.century.sjt.R;
import com.century.sjt.activity.BaseActivity;
import com.century.sjt.widget.TitleBar.SjtTitleBar;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ImgFileListActivity extends BaseActivity implements OnItemClickListener {
	private SjtTitleBar titleBar;
	private ImageButton btnSys;                                     //返回按钮
	private TextView mTitle;                                        //程序标题
	private LinearLayout leftLinLayout;                             //左边的线性布局

	ListView listView;
	Util util;
	ImgFileListAdapter listAdapter;
	List<FileTraversal> locallist;

	private String content;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.imgfilelist);

		Intent intent  =this.getIntent();
		content = intent.getStringExtra("content");

//		mTitle = (TextView) findViewById(R.id.img_title);
//		mTitle.setText("选择文件夹");
//		btnSys = (ImageButton) findViewById(R.id.btn_sys);
//		btnSys.setImageResource(R.drawable.ease_mm_title_back);
//		btnSys.setClickable(false);
//		leftLinLayout = (LinearLayout) findViewById(R.id.leftLinLayout);
//		leftLinLayout.setOnClickListener(new View.OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				finish();
//				overridePendingTransition(R.animator.in_from_left, R.animator.out_to_right);
//			}
//		});
		titleBar = (SjtTitleBar) findViewById(R.id.title_bar);
		//       标题栏
		titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				finish();
			}
		});
		titleBar.setTitle(getResources().getString(R.string.tab_choose_file));

		listView=(ListView) findViewById(R.id.listView1);
		util=new Util(this);
		locallist=util.LocalImgFileList();
		List<HashMap<String, String>> listdata=new ArrayList<HashMap<String,String>>();
		Bitmap bitmap[] = null;
		if (locallist!=null) {
			bitmap=new Bitmap[locallist.size()];
			for (int i = 0; i < locallist.size(); i++) {
				HashMap<String, String> map=new HashMap<String, String>();
				map.put("filecount", locallist.get(i).filecontent.size()+getString(R.string.text_picture));
				map.put("imgpath", locallist.get(i).filecontent.get(0)==null?null:(locallist.get(i).filecontent.get(0)));
				map.put("filename", locallist.get(i).filename);
				listdata.add(map);
			}
		}
		listAdapter=new ImgFileListAdapter(this, listdata);
		listView.setAdapter(listAdapter);
		listView.setOnItemClickListener(this);
		
	}

	@Override
	protected void initView() {

	}

	@Override
	protected void initEvent() {

	}

	@Override
	protected void initData() {

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Intent intent=new Intent(this,ImgsActivity.class);
		Bundle bundle=new Bundle();
		bundle.putParcelable("data", locallist.get(arg2));
		intent.putExtras(bundle);
		intent.putExtra("content",content);
		startActivity(intent);

	}
	
}
